home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Tools & Goodies / IntlTest / Sources / View.cpp < prev    next >
Encoding:
Text File  |  1996-09-12  |  3.6 KB  |  141 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                View.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                Mary Boetcher
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "IntlTest.hpp"
  13.  
  14. #ifndef VIEW_H
  15. #include "View.h"
  16. #endif
  17.  
  18. #ifndef DEFINES_K
  19. #include "Defines.k"
  20. #endif
  21.  
  22. // ----- Framework Layer -----
  23.  
  24. #ifndef FWFRAME_H
  25. #include "FWFrame.h"
  26. #endif
  27.  
  28. #ifndef FWCONTXT_H
  29. #include "FWContxt.h"
  30. #endif
  31.  
  32. // ----- OS Layer -----
  33.  
  34. #ifndef FWODGEOM_H
  35. #include "FWODGeom.h"
  36. #endif
  37.  
  38. #ifndef FWRECT_H
  39. #include "FWRect.h"
  40. #endif
  41.  
  42. #ifndef FWRECSHP_H
  43. #include "FWRecShp.h"
  44. #endif
  45.  
  46. // ----- OpenDoc Includes -----
  47.  
  48. #ifndef SOM_Module_OpenDoc_StdProps_defined
  49. #include <StdProps.xh>
  50. #endif
  51.  
  52. //========================================================================================
  53. // RunTime Info
  54. //========================================================================================
  55.  
  56. #ifdef FW_BUILD_MAC
  57. #pragma segment odfIntlTest
  58. #endif
  59.  
  60. //========================================================================================
  61. // CIntlTestView
  62. //========================================================================================
  63.  
  64. FW_DEFINE_CLASS_M1(CIntlTestView, FW_CSuperView);
  65.  
  66. //----------------------------------------------------------------------------------------
  67. // CIntlTestView::CIntlTestView
  68. //----------------------------------------------------------------------------------------
  69.  
  70. CIntlTestView::CIntlTestView(Environment* ev, FW_CSuperView* container, 
  71.                              const FW_CRect& contentRect, const FW_CPoint& extent)
  72. :    FW_CSuperView(ev, container, contentRect, 0, extent, FW_kNoScrolling)
  73. {
  74.     // Adjust the bounds but don't redraw now
  75.     CenterInFrame(ev, contentRect.Size(), FW_kDontRedraw);
  76. }
  77.  
  78. //----------------------------------------------------------------------------------------
  79. // CIntlTestView::~CIntlTestView
  80. //----------------------------------------------------------------------------------------
  81.  
  82. CIntlTestView::~CIntlTestView()
  83. {
  84. }
  85.  
  86. //----------------------------------------------------------------------------------------
  87. // CIntlTestView::Draw
  88. //----------------------------------------------------------------------------------------
  89.  
  90. void CIntlTestView::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  91. {
  92.     // Set up drawing context for this view
  93.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  94.  
  95.     // Erase with white first 
  96.     FW_CRect invalidRect;
  97.     vc.GetClipRect(invalidRect);
  98.     FW_CRectShape::RenderRect(vc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  99. }
  100.  
  101. //----------------------------------------------------------------------------------------
  102. // CIntlTestView::CenterInFrame
  103. //----------------------------------------------------------------------------------------
  104.  
  105. void CIntlTestView::CenterInFrame(Environment* ev, FW_CPoint& contentSize, FW_ERedrawVerb redraw)
  106. {
  107.     FW_CPoint    viewSize(GetSize(ev));
  108.     FW_CPoint    viewExtent(GetExtent(ev));
  109.     FW_CPoint    viewLoc;
  110.  
  111.     // Center the content view if it's smaller, or align it if it's bigger
  112.     if (viewSize != contentSize) 
  113.     {    
  114.         if (contentSize.x > viewExtent.x) 
  115.         {
  116.             viewLoc.x = FW_Half(contentSize.x - viewExtent.x);
  117.             viewSize.x = viewExtent.x;
  118.         }
  119.         else 
  120.         { 
  121.             viewLoc.x = FW_kFixed0;
  122.             viewSize.x = contentSize.x;
  123.         }
  124.         
  125.         if (contentSize.y > viewExtent.y) 
  126.         {
  127.             viewLoc.y = FW_Half(contentSize.y - viewExtent.y);
  128.             viewSize.y = viewExtent.y;
  129.         }
  130.         else 
  131.         {
  132.             viewLoc.y = FW_kFixed0;
  133.             viewSize.y = contentSize.y;
  134.         }
  135.         
  136.         SetLocation(ev, viewLoc, redraw);
  137.         SetSize(ev, viewSize, redraw);
  138.     }    
  139. }
  140.  
  141.